home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 38.9 KB | 1,140 lines | [TEXT/MPS ] |
- // UGridView.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __UGRIDVIEW__
- #define __UGRIDVIEW__
-
- // MacApp
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UITERATOR__
- #include "UIterator.h"
- #endif
-
- #ifndef __UTRACKER__
- #include "UTracker.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- // Toolbox
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TDocument;
- class TDragItem;
- class TToolboxEvent;
-
-
- //----------------------------------------------------------------------------------------
- // Boolean for Adornment
- //----------------------------------------------------------------------------------------
-
- const Boolean kAdorn = TRUE;
- const Boolean kDontAdorn = FALSE;
-
-
- //----------------------------------------------------------------------------------------
- // Booleans for SetSelection
- //----------------------------------------------------------------------------------------
-
- const Boolean kExtend = TRUE;
- const Boolean kDontExtend = FALSE;
-
- const Boolean kHighlight = TRUE;
- const Boolean kDontHighlight = FALSE;
-
- const Boolean kSelect = TRUE;
- const Boolean kDeSelect = FALSE;
-
-
- //----------------------------------------------------------------------------------------
- // Typedefs
- //----------------------------------------------------------------------------------------
-
- typedef CPoint GridCell;
- // A cell is a QuickDraw point
-
- enum GridViewPart { badChoice, inCell, inRow, inColumn, inVertex };
-
-
- //----------------------------------------------------------------------------------------
- // RunArrayChunk
- //----------------------------------------------------------------------------------------
-
- typedef struct RunArrayChunk
- {
- short count; // Number of consecutive items with this
- // value
-
- short value; // The value represented by this chunk
- } *ChunkArrayPtr;
-
-
- //----------------------------------------------------------------------------------------
- // TRunArray: The run array class is used to maintain the column widths and row heights.
- // Entries in the array are values for a given item, where the items are indexed from one.
- // fNoOfItems indicates the number of items (and values) in the array. The values are
- // maintained in "chunks" which lump together consecutive items with the same value. A
- // variable length array, fChunks, is used to store the chunks. It is indexed from zero.
- //----------------------------------------------------------------------------------------
-
- class TRunArray : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TRunArray();
- // Constructor
-
- void IRunArray();
- // Initializes a run array to have zero items.
-
- virtual ~TRunArray();
- // Frees the fChunks field which is a handle to the chunks, before calling
- // Inherited::Free.
-
- void InsertItems(short firstItem,
- short noOfItems,
- short value);
- // Inserts the indicated items into the run array, all of which have the given
- // value.
-
- void DeleteItems(short firstItem,
- short noOfItems);
- // Deletes the indicated items from the run array.
-
- Boolean FindChunk(short item,
- short& chunk,
- short& indexInChunk,
- long& theTotal);
- // Returns information about a given item in the run array. chunk indicates the
- // chunk in which the item is located, where zero is the first chunk in the run
- // array. indexInChunk is the location of the item withinin the chunk. Note that
- // the chunk indexes are one-based--the first item in the chunk is index 1.
- // theTotal is the sum of values up to, but not including, the chunk in which the
- // given item is located. FindChunk returns false if the given item is outside the
- // range of items in the run-array (i.e. item < 1 or item > fNoOfItems), or the
- // given item is not represented in a chunk (i.e. a bug).
- //
- // Example: Item Value Chunk indexInChunk theTotal
- // 10501000
- // 20502000
- // 32011010
- // 43521030
- // 53522030
- // 61031100
-
- short FindItem(long theTotal);
- // Returns the item number for which the sum of the values exceeds theTotal, or
- // zero if theTotal is outside the sum of values represented by the run array.
-
- short GetValue(short item);
- // Returns the value for the given item.
-
- long SumValues(short firstItem, short noOfItems);
- // Returns the sum of the values over the given items.
-
- inline RunArrayChunk& ChunkAt(ArrayIndex chunkIndex)
- { return *(RunArrayChunk*)(*fChunks)[chunkIndex]; }
- // returns a reference to the indexed chunk
-
- inline long GetTotal()
- { return fTotal; }
-
- inline void SetTotal(long newTotal)
- { fTotal = newTotal; }
-
- inline short GetNoOfChunks()
- { return fNoOfChunks; }
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- long fTotal; // The sum of the values in the run array
-
- short fNoOfChunks; // Number of chunks in the run array
-
- protected:
- TDynamicArray* fChunks; // The chunks themselves.
-
- long fLastTotal; // cache the last total calculated
-
- short fLastItem; // cache the last item found
-
- short fLastChunk; // cache the last chunk found
-
- short fLastIndex; // cache the last index used
-
- short fNoOfItems; // Number of items (values) in this
- // run-array
- };
-
-
- //----------------------------------------------------------------------------------------
- // TGridView: TGridView forms the base class for a building block that allows the creation
- // of views that can contain and manage cells, similar to a spreadsheet.
- //----------------------------------------------------------------------------------------
-
- class TGridView : public TView
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TGridView();
- // Constructor
-
- void IGridView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short numOfRows,
- short numOfCols,
- short rowHeight,
- short colWidth,
- Boolean adornRows,
- Boolean adornCols,
- short rowInset,
- short colInset,
- Boolean singleSelection);
- // Initialize the gridview. If numOfRows or numOfCols is non-zero then the
- // gridview is initialized to the specified size using rowHeight and colWidth if
- // the sizedeterminer is sizeVariable. If either adorn is kDontAdorn, then that
- // adorn will not be called.
-
- virtual TObject* Clone();
- // calls Inherited::Clone and then clones owned objects
-
- virtual ~TGridView();
- // Free the TGridView object
-
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFields(TStream* aStream); // override
-
- virtual void WriteFields(TStream* aStream); // override
-
- //------------------------------------------------------------------------------------
- // Inherited Methods(OVERRIDE)
- //------------------------------------------------------------------------------------
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber); // Override
- // Handles the Select All menu command
-
- virtual VRect CalcMinFrame();
- // Sets the extent of the view.
-
- virtual void DoHighlightSelection(HLState fromHL, HLState toHL);
- // Do highlighting
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);
- // Handle mouse commands
-
- virtual void Draw(const VRect& area);
- // Calls DrawRangeOfCells and AdornRow/ Col as appropriate.
-
-
- //------------------------------------------------------------------------------------
- // UGridView Methods to OVERRIDE
- //------------------------------------------------------------------------------------
-
- virtual void AdornCol(short aCol, const VRect& area);
- // If fAdornCol is true, this method is called to draw the column adornments.
-
- virtual void AdornRow(short aRow, const VRect& area);
- // If fAdornRow is true, this method is called to draw the rowadornments.
-
- virtual Boolean CanSelectCell(GridCell aCell);
- // This method checks to see if a cell can be seleced. By default, this method
- // always returns true.
-
- virtual void HighlightCells(RgnHandle theCells, HLState fromHL, HLState toHL);
- // Highlights the cells in theCells according to the given highlight state.
-
- virtual void DrawRangeOfCells(GridCell startCell,
- GridCell stopCell,
- const VRect& aRect);
- // This method calls DrawCell for each cell in need of re-drawing.
-
- virtual void DrawCell(GridCell aCell, const VRect& aRect);
- // This method draws each individual cell.IT MUST BE OVERRIDDEN!
-
-
- //------------------------------------------------------------------------------------
- // General UGridView Methods
- //------------------------------------------------------------------------------------
-
- VRect CellToVRect(GridCell aCell) const;
- inline void CellToVRect(GridCell aCell, VRect& theVRect) const
- { theVRect = CellToVRect(aCell); }
- // Get the rectangle bounding a given cell. This includes the row and column
- // insets.
-
- VRect ColToVRect(short aCol, short numOfCols) const;
- inline void ColToVRect(short aCol, short numOfCols, VRect& theVRect) const
- { theVRect = ColToVRect(aCol, numOfCols); }
- // Get the rectangle bounding the given columns. This includes the cells in the
- // row or column and the row or column insets.
-
- VRect RowToVRect(short aRow, short numOfRows) const;
- inline void RowToVRect(short aRow, short numOfRows, VRect& theVRect) const
- { theVRect = RowToVRect(aRow, numOfRows); }
- // Get the rectangle bounding the given rows. This includes the cells in the row
- // or column and the row or column insets.
-
- void CellsToPixels(RgnHandle theCells, RgnHandle thePixels);
- // Returns in thePixels a region that contains all of the cells in theCells.
-
- virtual void DelColAt(short aCol, short numOfCols);
- // Delete the specified columns, starting at 'aCol' with the number to be deleted
- // 'numOfCols'.This causes a redraw of only the necessary cells.
-
- virtual void DelRowAt(short aRow, short numOfRows);
- // Delete the specified rows, starting at 'aRow' with the number of to be deleted
- // 'numOfRows'.This causes a redraw of only the necessary cells.
-
- virtual void DelColFirst(short numOfCols);
- // Delete the specified number of columns from the beginning of the list.This
- // causes a redraw of only the necessary cells.
-
- virtual void DelRowFirst(short numOfRows);
- // Delete the specified number of rows from the beginning of the list.This causes
- // a redraw of only the necessary cells.
-
- virtual void DelColLast(short numOfCols);
- // Delete the specified number of columns from the last cell of the list.This
- // causes a redraw of only the necessary cells.
-
- virtual void DelRowLast(short numOfRows);
- // Delete the specified number of rows from the last cell of the list.This causes
- // a redraw of only the necessary cells.
-
- virtual GridCell FirstSelectedCell();
- // Returns the top left cell in the selection range, if any
-
- short GetColWidth(short aCol) const;
- // Return the width for the specifiedcolumn.
-
- short GetRowHeight(short aRow) const;
- // Return the height for the specified row .
-
- virtual GridViewPart IdentifyPoint(const VPoint& thePoint,
- GridCell& aCell);
- // Return the GridViewPart (inCell, inColumn, inRow, inVertex) in which the
- // specified VPoint lies. The "vertex" is the area where a row and column meet.
-
- virtual void InsColBefore(short aCol, short numOfCols, short aWidth);
- // Insert the specified columns before the column given.The widths of the columns
- // are all set to the specified aWidth.
-
- virtual void InsRowBefore(short aRow, short numOfRows, short aHeight);
- // Insert the specified rows before the row given.The heights of the rows are all
- // set to the specified aHeight.
-
- virtual void InsColFirst(short numOfCols, short aWidth);
- // Insert the specified number of columns at the beginning of the list.The widths
- // of the columns are all set to the specified aWidth.
-
- virtual void InsRowFirst(short numOfRows, short aHeight);
- // Insert the specified number of rows at the beginning of the list.The heights of
- // the rows are all set to the specified aHeight.
-
- virtual void InsColLast(short numOfCols, short aWidth);
- // Insert the specified number columns at the end of the list.The widths of the
- // columns are all set to the specified aWidth.
-
- virtual void InsRowLast(short numOfRows, short aHeight);
- // Insert the specified number of rows at the end of the list.The heights of the
- // rows are all set to the specified aHeight.
-
- virtual void InvalidateCell(GridCell aCell);
- // Cause a cell to be marked invalid (in need of re-drawing).
-
- virtual void InvalidateSelection();
- // Cause the rectangle bounding the selections to be marked invalid (in need of
- // re-drawing).
-
- virtual Boolean IsCellSelected(GridCell aCell);
- // Check if the specified cell is currently selected.
-
- virtual Boolean IsAnyCellSelected();
- // Returns true if any cell is currently selected.
-
- virtual GridCell LastSelectedCell();
- // Returns the bottom right cell in the selection range, if any
-
- virtual void ScrollSelectionIntoView(Boolean redraw); // Override
- // Scroll the selection into view.
-
- virtual void SetColWidth(short aCol, short numOfCols, short aWidth);
- // Set the width of the specified columns to that given.
-
- virtual void SetRowHeight(short aRow, short numOfRows, short aHeight);
- // Set the height of the specified rows to that given.
-
- virtual void SelectCell(GridCell theCell,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select);
- // Set the current selection to the specified cell. Sets up a region and then
- // calls SetSelection.
-
- virtual void SetEmptySelection(Boolean highlight);
- // Set the current selection to be empty or nothing. If highlight is kHighlight
- // then the appropriate highlighting is performed.
-
- virtual void SetSelection(RgnHandle cellsToSelect,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select);
- // Set the current selections to the specified region. If extend is kExtend then
- // cellsToSelect is "added" to that already selected, if highlight is kHighlight
- // then cellsToSelect is highlighted as well. IF select is kSelect then
- // cellsToSelect is selected, if kDeSelect then de-selected
-
- virtual void SetSelectionRect(const CRect& selectionRect,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select);
- // Set the current selections to the specified rectangle. and call SetSelection.
-
- virtual void SetSingleSelection(Boolean theSetting);
- // If true then only one item/ cell can be selected at a time
-
- GridCell VPointToCell(const VPoint& aPoint) const;
- // Determine the cell in which a given CPoint lies, or (0, 0) if the given CPoint
- // doesn't lie within any cell.
-
- GridCell VPointToLastCell(const VPoint& aPoint) const;
- // Returns the cell in which the given CPoint lies, or the last cell of the row/
- // column if the horizontal/ vertical coordinate lies beyond the last cell of the
- // row/ column.
-
- #if qDrag
- //------------------------------------------------------------------------------------
- // Drag and Drop Methods
- //------------------------------------------------------------------------------------
-
- virtual RgnHandle DoMakeDragCursorRegion(); // Override
-
- virtual Boolean WillDrag(const VPoint& localMouse, const RgnHandle dragCursorRegion); // Override
-
- virtual void DoDragEnter(); // Override
-
- virtual void DoDragLeave(); // Override
-
- virtual void DoDragWithin(const VPoint& localMouse); // Override
-
- virtual void DrawCellCaret(GridCell targetCell);
-
-
- #endif // qDrag
-
- protected:
- virtual void AddStrip(RgnHandle thePixels,
- VHSelect direction,
- short& startOfStrip,
- short endOfStrip,
- CRect& stripRect,
- short row,
- short col,
- VRect& pixels,
- VRect& previousPixels,
- CRect& prevStripRect);
- // Called by CellsToPixels to add a strip of cells to thePixels.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TRunArray* fColWidths; // bag containing col widths
-
- TRunArray* fRowHeights; // bag containing row heights
-
- RgnHandle fSelections; // Region of currently selected cells
-
- RgnHandle fHLRegion; // Region of cells to be highlighted. This
- // will be different from fSelections
- // while selection with the mouse is
- // taking place.
-
- RgnHandle fTemporarySelections; // Used by SetSelectionRect
-
- short fNumOfRows; // number of rows
-
- short fNumOfCols; // number of columns
-
- short fRowInset; // Number of pixels between cell rows
-
- short fColInset; // Number of pixels between cell cols
-
- Boolean fAdornRows; // Draw adornment for rows?
-
- Boolean fAdornCols; // Draw adornment for columns?
-
- Boolean fSingleSelection; // only one cell selected at a time?
-
- #if qDrag
-
- protected:
-
- GridCell fLastTargetCell;
-
- unsigned long fLastCaretTime;
-
- Boolean fCaretIsShown;
-
- #endif //qDrag
- };
-
-
- //----------------------------------------------------------------------------------------
- // TTextGridView: A sub-class of TGridView that can handle the display of text in its
- // cells.
- //----------------------------------------------------------------------------------------
-
- class TTextGridView : public TGridView
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialization and Free Methods
- //------------------------------------------------------------------------------------
-
- TTextGridView();
- // Constructor
- virtual ~TTextGridView();
- // Destructor
-
- void ITextGridView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short numOfRows,
- short numOfCols,
- short rowHeight,
- short colWidth,
- Boolean adornRows,
- Boolean adornCols,
- short rowInset,
- short colInset,
- Boolean singleSelection,
- const TextStyle& itsTextStyle);
- // Initialize the TextGridView. If numOfRows or numOfCols is non-zero then the
- // gridview is initialized to the specified size. The row and height of the cells
- // is determine by the font size, style etc. The default size may be changed with
- // calls to the the SetRowHeight and SetColWidth methods. If either adorn is
- // kDontAdorn, then that adorn will not be called. The "Insets" allow space
- // between cells and may be used to draw row and column adornments.
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFields(TStream* aStream); // override
-
- virtual void WriteFields(TStream* aStream); // override
-
- //------------------------------------------------------------------------------------
- // Methods To OVERRIDE
- //------------------------------------------------------------------------------------
-
- virtual void GetText(GridCell aCell, CStr255& aString);
- // This routine gets the text to be draw in a given cell. IT MUST BE OVERRIDDEN!
-
- #if qDrag
- //------------------------------------------------------------------------------------
- // Drag and Drop Methods
- //------------------------------------------------------------------------------------
-
- virtual void DoAddDragContent();
-
- virtual void DoFulfillPromise(TDragItem* promisedItem);
-
- #endif // qDrag
- //------------------------------------------------------------------------------------
- // General Methods
- //------------------------------------------------------------------------------------
-
- virtual void DrawCell(GridCell aCell, const VRect& aRect);
- // Calls GetText and then draws the text
-
- virtual Boolean Focus();
- // Calls Inherited::Focus and calls SetUpFont
-
- virtual void SetUpFont();
- // Sets up the font for this view.
-
- virtual void SetPen();
- // Sets the font characteristics of the current port. Called at the beginning of
- // the Draw method.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TextStyle fTextStyle; // The text style (color, size, etc. )
-
- short fTextStyleRsrcID; // Rsrc ID of 'TxSt' resource which has
- // TextStyle information.
-
- short fJustification; // Justification of text cells
-
- short fLineHeight; // height of each item including leading
-
- short fLineAscent; // pos. of baseline relative to top of
- // line
-
- Boolean fPreferOutline; // prefer outline fonts?
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TTextListView: This subclass of TTextGridView handles lists in a manner similar to the
- // List Manager in the toolbox. These lists typically consist of single columns and the
- // case of this subclass handle the placeme { Initialization and Free Methods
- //----------------------------------------------------------------------------------------
-
- class TTextListView : public TTextGridView
- {
- MA_DECLARE_CLASS;
-
- public:
- TTextListView();
- // Constructor
- virtual ~TTextListView();
- // Destructor
-
- void ITextListView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- short numOfItems,
- short rowHeight,
- short colWidth,
- Boolean adornRows,
- Boolean adornCols,
- short rowInset,
- short colInset,
- Boolean singleSelection,
- const TextStyle& itsTextStyle);
- // Initialize the TextListView. If numOfItems is non-zero then the listview is
- // initialized to the specified size. The width and height of the items are
- // determined by the font size, style etc. The default size may be changed with
- // calls to the the SetItemHeight and SetItemWidth methods. The "Insets" allow
- // space between items.
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Methods To OVERRIDE
- //------------------------------------------------------------------------------------
-
- virtual void GetItemText(short anItem, CStr255& aString);
- // Get the text to be drawn for a given item. THIS METHOD MUST BE OVERRIDDEN !!
-
- virtual short GetItemIndexOrdered(short nthItem);
- // Override this method if you are using the key selection behavior and the items
- // returned by GetItemText are not in alpha order. Return the position in the text
- // list of the 'nthItem' in alpha order.
-
- virtual Boolean CanSelectItem(short anItem);
- // Determine if the item is selectable
-
-
- //------------------------------------------------------------------------------------
- // General Methods
- //------------------------------------------------------------------------------------
-
- virtual Boolean CanSelectCell(GridCell aCell);
- // This method checks to see if a cell can be selected. This method simply calls
- // CanSelectItem
-
- virtual void DelItemAt(short anItem, short numOfItems);
- // Delete the specified items.This causes a redraw of only the necessary cells.
-
- virtual void DelItemFirst(short numOfItems);
- // Delete the specified items.This causes a redraw of only the necessary cells.
-
- virtual void DelItemLast(short numOfItems);
- // Delete the specified items.This causes a redraw of only the necessary cells.
-
- virtual void DoKeySelection(const CStr255& selectionString);
- // Selection the proper element in this list view based on the partial CString
- // 'selectionString'. This will be called by the key selection behavior if one is
- // added to this view.
-
- virtual short GetItemHeight(short anItem);
- // Return the height of the specified item.
-
- virtual short GetItemWidth();
- // Return the width of the view.
-
- virtual void GetText(GridCell aCell, CStr255& aString);
- // Calls GetItemText with an item number.
-
- virtual void InsItemBefore(short anItem, short numOfItems);
- // Insert numOfItems before anItem in the list.
-
- virtual void InsItemFirst(short numOfItems);
- // Insert numOfItems at the beginning of the list.
-
- virtual void InsItemLast(short numOfItems);
- // Insert numOfItems at the end of the list.
-
- virtual Boolean IsItemSelected(short anItem);
- // Check if the specified item is currently selected.
-
- virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
- // Resize the view.
-
- virtual void SelectCell(GridCell theCell,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select);
- // Calls SelectItem with the appropriate item number
-
- virtual void SelectItem(short anItem,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select);
- // Select the given item. If extend is true then the item is added to the current
- // selection. Otherwise the current selection is deselected. If highlight is true
- // then the selected item is highlighted.
-
- virtual void SetItemHeight(short anItem,
- short numOfItems,
- short aHeight);
- // Set the height of an item to be different from the default.This changes the
- // height of only the specified items.
-
- virtual void SetItemWidth(short aWidth);
- // Set the width of the view to aWidth. (This changes the width of all the items.
-
- virtual short FirstSelectedItem();
- // Returns the first item selected.
-
- virtual short LastSelectedItem();
- // Returns the last item selected.
-
- virtual void InvalidateItem(short anItem);
- // Invalidates the given item, causing it to be redrawn
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand
- //----------------------------------------------------------------------------------------
-
- class TCellSelectCommand : public TTracker
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TCellSelectCommand();
- // Constructor
-
- void ICellSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey);
- // Initialize the command object.
-
- virtual ~TCellSelectCommand();
- // If the region fPreviousSelection and fDifference are not NULL then dispose of them
- // before calling Inherited::Free.
-
- virtual void TrackFeedback(TrackPhase aTrackPhase,
- const VPoint& anchorPoint,
- const VPoint& previousPoint,
- const VPoint& nextPoint,
- Boolean mouseDidMove,
- Boolean turnItOn);
- // Override this method to give feedback while the mouse button is down. The
- // default does nothing.
-
- virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
- VPoint& anchorPoint,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove);
- // Track the mouse when the button is down.
-
- virtual void DoIt();
- // The method that will do the actual task to be performed by the command.MUST BE
- // OVERRIDDEN.
-
- virtual void ComputeAnchorCell(GridCell& clickedCell);
- // Computes the cell that the mouse is first clicked in when making a selection.
-
- virtual void ComputeNewSelection(GridCell& clickedCell);
- // Calculate what the new selection should be.
-
- virtual void HighlightNewSelection();
- // Highlight the new selection.
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- public:
- TGridView* fGridView; // The associated GridView
- RgnHandle fThisSelection;
- RgnHandle fPreviousSelection;
- RgnHandle fDifference;
- GridCell fAnchorCell;
- GridCell fPreviousCell;
- Boolean fShiftKey; // Shift Key down?
- Boolean fCommandKey; // Command Key down?
- Boolean fDeselecting;
- };
-
-
- //----------------------------------------------------------------------------------------
- // TRCSelectCommand: An abstract superclass for row and column selection.
- //----------------------------------------------------------------------------------------
-
- class TRCSelectCommand : public TCellSelectCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TRCSelectCommand();
- // Empty constructor to satisfy compiler.
- virtual ~TRCSelectCommand();
- // Destructor
-
- void IRCSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey);
- // Initialization method for TRCSelectCommand.
-
- virtual void ComputeNewSelection(GridCell& clickedCell);
- // Computes the new selection.
-
- virtual TTracker* TrackMouse(TrackPhase aTrackPhase,
- VPoint& anchorPoint,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove);
- // Track the mouse during selection.
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TRowSelectCommand: A subclass that performs selections on rows
- //----------------------------------------------------------------------------------------
-
- class TRowSelectCommand : public TRCSelectCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TRowSelectCommand();
- // Empty constructor to satisfy compiler.
- virtual ~TRowSelectCommand();
- // Destructor
-
- void IRowSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey);
- // Initialization of command.
-
- virtual void ComputeAnchorCell(GridCell& clickedCell);
- // Override of method to perform computations specific to row selection.
-
- virtual void ComputeNewSelection(GridCell& clickedCell);
- // Override of method to perfom computation of new selection specific to row
- // selection.
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TColumnSelectCommand: A subclass that handles the selection of columns in a GridView.
- //----------------------------------------------------------------------------------------
-
- class TColumnSelectCommand : public TRCSelectCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TColumnSelectCommand();
- // Empty constructor to satisfy compiler.
- virtual ~TColumnSelectCommand();
- // Destructor
-
- void IColumnSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey);
- // Initialization method.
-
- virtual void ComputeAnchorCell(GridCell& clickedCell);
- // Override of method to perform computations specific to column selection.
-
- virtual void ComputeNewSelection(GridCell& clickedCell);
- // Override of method to perform computation of new selection specific to column
- // selection.
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator: an iterator class designed to replace the EachRowDo method of
- // TGridView. APW 6-13
- //----------------------------------------------------------------------------------------
-
- class CRowIterator : public CIterator
- {
- public:
- static const short kNullRow;
-
- CRowIterator(const TGridView* itsGridView,
- short startRow,
- short stopRow,
- Boolean itsForward);
-
- CRowIterator(const TGridView* itsGridView, Boolean itsForward);
- CRowIterator(const TGridView* itsGridView);
- short FirstRow();
- short NextRow();
- Boolean More(); //override!!!
- void Reset(); //override!!!
-
- protected:
- void Advance(); //override!!!
-
- private:
- void IRowIterator(const TGridView* itsGridView, //called exclusively by the
- short startRow, //constructors of this class.
- short stopRow,
- Boolean itsForward);
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- short fCurrentRow;
- short fFirstRow;
- short fLastRow;
- Boolean fIterateForward;
- };
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator: an iterator class designed to replace the EachColumnDo
- // method of TGridView. APW 6-13
- //----------------------------------------------------------------------------------------
-
- class CColumnIterator : public CIterator
- {
- public:
- static const short kNullColumn;
-
- CColumnIterator(const TGridView* itsGridView,
- short startColumn,
- short stopColumn,
- Boolean itsForward);
-
- CColumnIterator(const TGridView* itsGridView, Boolean itsForward);
- CColumnIterator(const TGridView* itsGridView);
- short FirstColumn();
- short NextColumn();
- Boolean More(); //override!!!
- void Reset(); //override!!!
-
- protected:
- void Advance(); //override!!!
-
- private:
- void IColumnIterator(const TGridView* itsGridView, //to be called exclusively
- short startColumn, //by the constructors of
- short stopColumn, //this class.
- Boolean itsForward);
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- short fCurrentColumn;
- short fFirstColumn;
- short fLastColumn;
- Boolean fIterateForward;
- };
-
- //----------------------------------------------------------------------------------------
- // CCellIterator: an iterator class designed to replace the EachCellDo method
- // of TGridView. APW 6-13
- //----------------------------------------------------------------------------------------
-
- class CCellIterator : public CIterator
- {
- public:
- static const GridCell kNullCell;
- static const Boolean kIterateRowMajor;
-
- CCellIterator(const TGridView* itsGridView,
- GridCell startCell,
- GridCell stopCell,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor);
-
- CCellIterator(const TGridView* itsGridView,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor);
-
- CCellIterator(const TGridView* itsGridView);
-
- GridCell FirstCell();
-
- GridCell NextCell();
-
- Boolean More(); //override!!!
-
- void Reset(); //override!!!
-
- protected:
- void Advance(); //override!!!
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- CRowIterator fRowIterator;
- CColumnIterator fColumnIterator;
- GridCell fCurrentCell;
- Boolean fIterateRowMajor;
- };
-
-
- //----------------------------------------------------------------------------------------
- // CCellInRegionIterator: an iterator class designed to replace the EachInRegion method
- // of TGridView. APW 7-15
- //----------------------------------------------------------------------------------------
-
- class CCellInRegionIterator : public CCellIterator
- {
- public:
- CCellInRegionIterator(const TGridView* itsGridView,
- RgnHandle aRegion,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor);
-
- CCellInRegionIterator(const TGridView* itsGridView,
- RgnHandle aRegion);
-
- void Reset(); //override!!!
-
- protected:
- void Advance(); //override!!!
-
- Boolean CellIsInRegion();
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- RgnHandle fRegion;
-
- Boolean fIsRectangularRegion;
- };
-
- //----------------------------------------------------------------------------------------
- // CSelectedCellIterator: an iterator class designed to replace the EachSelectedCellDo method
- // of TGridView. APW 7-15
- //----------------------------------------------------------------------------------------
-
- class CSelectedCellIterator : public CCellInRegionIterator
- {
- public:
- CSelectedCellIterator(const TGridView* itsGridView,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor);
-
- CSelectedCellIterator(const TGridView* itsGridView);
-
- void Reset(); //override!!!
-
- };
-
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations. These are intended to be private, but are in the
- // interface so that you can use these regions if you override the methods that use them.
- //----------------------------------------------------------------------------------------
-
- extern RgnHandle pPixelsToHighlight; // Used by HighlightCells
-
- extern RgnHandle pPreviousSelection; // Used by SetSelection
-
- extern RgnHandle pDifference; // Used by SetSelection
-
- extern RgnHandle pVisibleCells; // Used by CellsToPixels
-
- extern RgnHandle pInvalidateRgn; // Used by InvalidateSelection
-
-
- //----------------------------------------------------------------------------------------
- // Global functions declarations.
- //----------------------------------------------------------------------------------------
-
- extern void InitUGridView();
- // Creates all the regions used by the GridView class and then sets the global flag
- // 'gUGridViewInitialized'.
-
-
- #endif
-
-
-